package com.tuniu.agents.common.entity.trip;

import java.util.List;
import java.util.stream.Collectors;

import com.tuniu.agents.common.vo.ApiResponse;

/**
 * Response class for extracting resources
 */
public class ExtractResourceResponse extends ApiResponse<ExtractResourceResponse.Data> {

    public static class Data{
        private List<Hotel> hotel;
        private List<POI> poi;
    
        public List<Hotel> getHotel() {
            return hotel;
        }
    
        public void setHotel(List<Hotel> hotel) {
            this.hotel = hotel;
        }
    
        public List<POI> getPoi() {
            return poi;
        }
    
        public void setPoi(List<POI> poi) {
            this.poi = poi;
        }
    
    
        public static class Hotel{
            private String name;
            private String url;
            private String match_name;
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
    
            public String getUrl() {
                return url;
            }
    
            public void setUrl(String url) {
                this.url = url;
            }
    
            public String getMatch_name() {
                return match_name;
            }
    
            public void setMatch_name(String match_name) {
                this.match_name = match_name;
            }
    
        }
        public static class POI{
            private String name;
            private String url;
            private String match_name;
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
    
            public String getUrl() {
                return url;
            }
    
            public void setUrl(String url) {
                this.url = url;
            }
    
            public String getMatch_name() {
                return match_name;
            }
    
            public void setMatch_name(String match_name) {
                this.match_name = match_name;
            }
    
        }

        public String toMarkdown(){
            if(hotel.isEmpty() && poi.isEmpty()){
                return "No matching resources found";
            }
            StringBuilder sb = new StringBuilder();
            sb.append("## Matching Resources\n");
            if(!hotel.isEmpty()){
                sb.append("### Hotels\n" +
                   "| Name | URL | Match Name |\n" +
                   "| --- | --- | --- |\n" +
                   hotel.stream()
                       .map(h -> "| " + h.getName() + " | " + h.getUrl() + " | " + h.getMatch_name() + " |")
                       .collect(Collectors.joining("\n")) +"\n");
            }
            if(!poi.isEmpty()){
                sb.append("### Attractions\n" +
                   "| Name | URL | Match Name |\n" +
                   "| --- | --- | --- |\n" +
                   poi.stream()
                       .map(p -> "| " + p.getName() + " | " + p.getUrl() + " | " + p.getMatch_name() + " |")
                       .collect(Collectors.joining("\n"))+"\n");
            }
            return sb.toString();
        }
    }
}
